import pymysql

# 创建连接对象
conn = pymysql.connect(
    host='localhost',
    port=3306,
    user='root',
    password='',
    database='test'
)

# 获取游标对象
cursor = conn.cursor()
sql = "select * from user;"
row_count = cursor.execute(sql)
print('sql执行影响的行数: {}'.format(row_count))

# 取出一行数据
#print(cursor.fetchone())

# 取出结果集中的所有数据
for row in cursor.fetchall():
    print(row)

# 关闭游标
cursor.close()
# 关闭连接1.test1.py
conn.close()

